package rrrmai.di.module;

import android.arch.persistence.room.Room;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.f2prateek.rx.preferences2.RxSharedPreferences;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rrrmai.room.database.AppDataBase;
import xgggh.activity.DIApplication;

/**
 * Created by summer on 2018/2/9.
 */


@Module
public class ApplicationModule {

    private DIApplication mApplication;
    @Inject
    public ApplicationModule(DIApplication app) {
        mApplication = app;
    }

    //@Singleton
    @Provides
    public DIApplication provideApplication() {
        return mApplication;
    }

    @Provides
    public RxSharedPreferences provideRxSharedPreferences(SharedPreferences sharedPreferences) {
        return RxSharedPreferences.create(sharedPreferences);
    }

    @Provides
    public SharedPreferences provideSharedPreferences() {
        return PreferenceManager.getDefaultSharedPreferences(mApplication);
    }

    @Provides
    public AppDataBase provideDataBase() {
        AppDataBase db = Room.databaseBuilder(mApplication,
                AppDataBase.class, "rrrmai").build();
        return db;
    }



}
